﻿//查询举报信息
var currentPage = 1; // 当前页
var pageSize = 18; // 每页显示多少条
var pageall = 0; // 总页数
var total = 0; // 总记录数
var isValid = 1;
var deptid = 0;
var IdList = "";
var result = "";
var deptname = "";
var starttime = "";
var endtime = "";

$(document).ready(function() {
    ShowInfo(currentPage); //未审核举报信息

});

function ShowInfo(currentPage) {
    var id = 0;
    var rolename = document.getElementById("rolename").value;
    var duserid = document.getElementById("duserid").value;
    var hCompetencesSh = document.getElementById("hCompetencesSh").value;
    if (hCompetencesSh != 1) {//数据服务部 1.有权修改审核，0，无权审核
        document.getElementById("div1").style.display = "none";

    }
    deptid = 0;
    $("#divAlert1").html("<img src=\"../images/loading.gif\" />"); // 清空列表
    $("#divAlert6").html("<img src=\"../images/loading.gif\" />"); // 清空列表 
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=ShowInfo&id=' + id + '&page=' + currentPage + '&pagesize=' + pageSize + '&isValid=' + isValid + '&deptid=' + deptid + '&IdList=' + IdList + '&rolename=' + rolename + '&duserid=' + duserid,
        timeout: '10000',
        error: function() {
        alert("修改失败！");
        },
        success: function(json) {
            ShowInfoCallBack(json);
        }
    });
}
function ShowInfoCallBack(response) {
    var json = eval("(" + response + ")");
    var record = json.record;
    var page = json.page;
    currentPage = page.currentpage;
    pageall = parseInt(page.pageall);
    total = page.total;
    if (record == null || record.length == 0) {
        $("#divAlert1").html(""); // 清空列表                
        $("#divAlert6").html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>");
        return;
    }
    var arr = [];
    arr.push("<table id='table1' width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
    arr.push("<tr>");
    arr.push("<td bgcolor='d3eaef' class='STYLE10' style='width:50px' >");
    arr.push("房源编号</td>");
    arr.push("<td bgcolor='d3eaef' class='STYLE10'  >");
    arr.push("物业名称</td>");
    arr.push("<td bgcolor='d3eaef' style='width:42px' class='STYLE10' >");
    arr.push("房号</td>");
    arr.push("<td  bgcolor='d3eaef' class='STYLE10'  >");
    arr.push("举报时间</td>");
    arr.push("<td bgcolor='d3eaef' class='STYLE10' >");
    arr.push("部门</td>");
    arr.push("<td bgcolor='d3eaef' class='STYLE10' style='width:50px' >");
    arr.push("举报人</td>");
    arr.push("<td  bgcolor='d3eaef' class='STYLE10' >");
    arr.push("举报内容</td>");
    
    arr.push("<td bgcolor='d3eaef' style='width:92px' class='STYLE10'  >");
    arr.push("操作</td>");
//    arr.push("<td bgcolor='d3eaef' class='STYLE10'  >");
//    arr.push("处理时间</td>");
//    arr.push("<td bgcolor='d3eaef' class='STYLE10' >");
//    arr.push("处理人</td>");
//    arr.push("<td bgcolor='d3eaef' class='STYLE10' >");
//    arr.push("处理结果</td>");
//    arr.push("</tr>");


   
    
    for (var i = 0; i < record.length; i++) {

      
        if (i % 2 == 0)
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF' style='cursor: pointer;' onclick=\"selectedTr('" + record[i].id + "','" + record[i].hid + "')\" >");
        else
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED' style='cursor: pointer;' onclick=\"selectedTr('" + record[i].id + "','" + record[i].hid + "')\" >");
       
        arr.push("<td  class='STYLE10' >");
        arr.push("" + record[i].hid + "</td>")
        arr.push("<td  class='STYLE10' >");
        arr.push("<a href='#' onclick=\"openDetail('" + record[i].housingid + "')\">" + record[i].buildname + "</a></td>");
        arr.push("<td style='width:42px' class='STYLE10'>");
        arr.push("" + record[i].roomno + "</td>");
        arr.push("<td  class='STYLE10'>");
        var infodate = record[i].informdate;
        arr.push("" + infodate.substr(5,infodate.length) + "</td>");
        arr.push("<td  class='STYLE10' >");
        arr.push("" + record[i].informdept + "</td>");
        arr.push("<td   class='STYLE10'>");
        arr.push("" + record[i].informuser + "</td>");
        arr.push("<td   class='STYLE10'>");
        arr.push("<font color='blue'>[" + record[i].reason + "]</font>" + record[i].dview + "</td>");
        
        arr.push("<td   class='STYLE10'>");
        if (isValid == 0) {
            arr.push("<a href=\"javascript:UpdateResult('" + record[i].id + "','1')\"><font color='red'>通过</font></a><a href=\"javascript:UpdateResult('" + record[i].id + "','0')\"><font color='red'>不通过</font></a></td>");
        } else if (isValid == 1) {
            arr.push("<a href=\"javascript:UpdateIsValid('" + record[i].id + "','0')\"><font color='red'>有效</font></a><a href=\"javascript:UpdateIsValid('" + record[i].id + "','2')\"><font color='red'>无效</font></a></td>");
        }
//        arr.push("<td  class='STYLE10'>");
//        if (record[i].duser == "") {
//            arr.push("</td>");
//        }
//        else {
//            arr.push("" + record[i].ddate + "</td>");
//        }

//        arr.push("<td   class='STYLE10'>");
//        arr.push("" + record[i].duser + "</td>");
//        arr.push("<td   class='STYLE10'>");

//        arr.push("" + record[i].dresult + "</td>");
        arr.push("</tr>");
    }
    arr.push("</table>");
    if (isValid == 1) {//为处理的审核举报信息
        $("#divAlert1").html(""); // 清空
        $("#divAlert1").html(arr.join('')); // 显示列表
        $("#divAlert2").html(""); // 清空
        if (pageall > 1) {
            var pageHtml = LexunJS.showPage2(currentPage, pageall, "ShowInfo"); // 分页
            $("#divAlert2").html(pageHtml);
        }
    } else if (isValid == 0) {//为处理的举报信息---数据服务部，直属经理，区域经理(一周内同个盘源超过三次的举报信息)
        $("#divAlert6").html("");
        $("#divAlert6").html(arr.join('')); // 显示列表
        $("#divAlert7").html(""); // 清空
        if (pageall > 1) {
            var pageHtml = LexunJS.showPage2(currentPage, pageall, "ShowInfo"); // 分页
            $("#divAlert7").html(pageHtml);
        }
    }
}

//查询处理结果
function SelectResultList(currentPage) {
    $("#divResult1").html("<img src=\"../images/loading.gif\" />"); // 清空列表
    $("#divResult3").html("<img src=\"../images/loading.gif\" />"); // 清空列表
    deptname = document.getElementById("dept").value;
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=SelectResultList&page=' + currentPage + '&pagesize=' + pageSize + '&isValid=' + isValid + '&result=' + result + '&IdList=' + IdList + '&deptname=' + deptname + '&time1=' + starttime + '&time2=' + endtime,
        timeout: '10000',
        error: function() {
         alert("修改失败！");
        },
        success: function(json) {
            ShowResultListCallBack(json);
        }
    });
}
function ShowResultListCallBack(response) {
    var json = eval("(" + response + ")");
    var record = json.record;
    var page = json.page;
    currentPage = page.currentpage;
    pageall = parseInt(page.pageall);
    total = page.total;
    if (record == null || record.length == 0) {
        $("#divResult1").html(""); // 清空列表
        $("#divResult3").html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>");
        return;
    }
    var hCompetencesSh = document.getElementById("hCompetencesSh").value;
    var ManagerInfo = document.getElementById("ManagerInfo").value;
    var arr = [];
    arr.push("<table id='table1' width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
    arr.push("<tr>");
    arr.push("<td height='25'bgcolor='d3eaef' style='width:50px' class='STYLE10'  >");
    arr.push("房源编号</td>")
    arr.push("<td height='25'bgcolor='d3eaef' class='STYLE10'  >");
    arr.push("物业名称</td>");
    arr.push("<td  height='25'bgcolor='d3eaef' style='width:30px' class='STYLE10''  >");
    arr.push("房号</td>");
    arr.push("<td  height='25'bgcolor='d3eaef' class='STYLE10'  >");
    arr.push("举报时间</td>");
    arr.push("<td  height='25'bgcolor='d3eaef' class='STYLE10'  >");
    arr.push("部门</td>");
    arr.push("<td  height='25'bgcolor='d3eaef'style='width:50px' class='STYLE10'  >");
    arr.push("举报人</td>");
    arr.push("<td  height='25'bgcolor='d3eaef' class='STYLE10'  >");
    arr.push("举报内容</td>");
    arr.push("<td  height='25'bgcolor='d3eaef' class='STYLE10' >");
    arr.push("处理时间</td>");
    arr.push("<td height='25'bgcolor='d3eaef' class='STYLE10' >");
    arr.push("处理人</td>");
    arr.push("<td  height='25'bgcolor='d3eaef' class='STYLE10'  >");
    arr.push("处理结果</td>");
    arr.push("<td height='25'bgcolor='d3eaef' class='STYLE10'  >");
    arr.push("建议处理</td>");
    if (isValid == 0 && hCompetencesSh == "1") {
        arr.push("<td  height='25'bgcolor='d3eaef' style='width:60px' class='STYLE10'  >");
        arr.push("操作</td>");
    } else
        if (isValid == 2 && hCompetencesSh == "1") {
        arr.push("<td  height='25'bgcolor='d3eaef' class='STYLE10'  >");
        arr.push("操作</td>");
    }
    arr.push("</tr>");
    for (var i = 0; i < record.length; i++) {
        if (i % 2 == 0)
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF' style='cursor: pointer;' onclick=\"selectedTr('" + record[i].id + "','" + record[i].hid + "')\" >");
        else
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED' style='cursor: pointer;' onclick=\"selectedTr('" + record[i].id + "','" + record[i].hid + "')\" >");

        arr.push("<td  class='STYLE10' >");
        arr.push("" + record[i].hid + "</td>");
        arr.push("<td  class='STYLE10' >");
        arr.push("<a href='#' onclick=\"openDetail('" + record[i].housingid + "')\">" + record[i].buildname + "</a></td>");
        arr.push("<td  class='STYLE10' >");
        arr.push("" + record[i].roomno + "</td>");
        arr.push("<td  class='STYLE10' >");
        var infodate = record[i].informdate;
        arr.push("" + infodate.substr(5,infodate.length) + "</td>");
        arr.push("<td  class='STYLE10' >");
        arr.push("" + record[i].informdept + "</td>");
        arr.push("<td  class='STYLE10' >");
        arr.push("" + record[i].informuser + "</td>");
        arr.push("<td   class='STYLE10'>");
        arr.push("<font color='blue'>[" + record[i].reason + "]</font>" + record[i].dview + "</td>");
        arr.push("<td  class='STYLE10' >");
        var ddate = record[i].ddate;
        arr.push("" + ddate.substr(5,ddate.length) + "</td>");
        arr.push("<td   class='STYLE10'>");
        arr.push("" + record[i].duser + "</td>");
        arr.push("<td  class='STYLE10' >");
        arr.push("" + record[i].dresult + "</td>");
        arr.push("<td  class='STYLE10' >");
        arr.push("" + record[i].advise + "</td>");
        if (isValid == 0 && hCompetencesSh == "1") {
            arr.push("<td  class='STYLE10' >");
            if (record[i].status == "1") {
                arr.push("<a href=\"javascript:UpdateHousingIsvalid('" + record[i].id + "','" + record[i].advise + "')\"><font color='red'>执行</font></a></td>");
            }
            else {
                arr.push("<a href='#'><font color='blue'>已执行</font></a></td>");
            }
        }
        else if (isValid == 2 && hCompetencesSh == "1") {
            arr.push("<td  class='STYLE10' >");
            arr.push("<a href=\"javascript:OpenInfo('" + record[i].informdeptid + "','" + record[i].housingid + "')\"><font color='red'>举报</font></a></td>");


        }
        arr.push("</tr>");
    }
    arr.push("</table>");
    if (isValid == 0) {///已通过的举报信息，数据服务部进行最后的操作（更新数据）
        $("#divResult1").html("");
        $("#divResult1").html(arr.join('')); // 显示列表
        $("#divResult2").html(""); // 清空
        if (pageall > 1) {
            var pageHtml = LexunJS.showPage2(currentPage, pageall, "SelectResultList"); // 分页
            $("#divResult2").html(pageHtml);
        }
    } else {///未通过的举报信息
        $("#divResult3").html("");
        $("#divResult3").html(arr.join('')); // 显示列表
        $("#divResult4").html(""); // 清空
        if (pageall > 1) {
            var pageHtml = LexunJS.showPage2(currentPage, pageall, "SelectResultList"); // 分页
            $("#divResult4").html(pageHtml);
        }
    }

}
// 跳转 num(跳到第几个标签)
function go_to(num) {
    var tabs = document.getElementById("div_tab").getElementsByTagName("a");
    for (var i = 1; i <= tabs.length; i++) {
        if (num == i) {
            tabs[i - 1].className = "y";
            document.getElementById("div" + i).style.display = "block";
        } else {
            tabs[i - 1].className = "";
            document.getElementById("div" + i).style.display = "none";
        }
    }

    switch (num) {
        case 1:
            isValid = 1;
            IdList = "";
            ShowInfo(currentPage); //未审核举报信息
            break;
        case 2:
            isValid = 0;
            IdList = document.getElementById("IdList").value;
            ShowInfo(currentPage); //为处理举报信息
            break;
        case 3:
            isValid = 0;
            result = "通过";
            IdList = document.getElementById("IdList").value;
            SelectResultList(currentPage); //已通过举报信息
            break;
        case 4:
            isValid = 2;
            result = "未通过";
            IdList = document.getElementById("IdList").value;
            SelectResultList(currentPage);
            break; //未通过举报信息

    }
}

//处理举报
function UpdateIsValid(id, isValid) {
    // ajax修改状态
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=p_housingInform_updateisValid&id=' + id + '&isValid=' + isValid,
        timeout: '10000',
        error: function() {
            alert("处理失败！");
        }, success: function(outmsg) {
            alert(outmsg);
            ShowInfo(1);

        }
    });

}

//修改房源状态
function UpdateHousingIsvalid(id, advise) {
    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=UpdateHousingIsvalid&id=' + id + '&advise=' + advise,
        timeout: '10000',
        error: function() {
        alert("处理失败！");
        }, success: function(outmsg) {
        alert(outmsg);
            isValid = 0;
            result = "通过";
            SelectResultList(currentPage);
        }
    });

}
function UpdateResult(id, dresult) {
    // ajax修改状态
    var dept = document.getElementById("dept").value;
    var deptid = document.getElementById("deptid").value;
    var duser = document.getElementById("duser").value;
    var duserid = document.getElementById("duserid").value;
    if (dresult == 1) {
        isValid = 0;
        result = "通过";
    } else {
        isValid = 2;
        result = "未通过";
    }

    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerHousing.ashx',
        data: 'act=UpdateResult&id=' + id + '&dept=' + dept + '&deptid=' + deptid + '&duser=' + duser + '&duserid=' + duserid + '&dresult=' + result + '&isValid=' + isValid,
        timeout: '10000',
        error: function() {
         alert("处理失败！");
        }, success: function(outmsg) {
            alert(outmsg);
            isValid = 0;
            deptid = 0;
            ShowInfo(1);

        }
    });

}
// 选中某行
function selectedTr(id, hid) {
    $("tr").removeClass("selected");
    $("#tr_" + id).addClass("selected");

    //window.open("HousingDetail.aspx?id=" + hid, "target", LexunJS.openParams());;
}

//弹出窗口
function OpenInfo(deptid, hid) {
    var path = "EstateShowInfo.aspx?deptid=" + deptid + '&hid=' + hid;
    var parameter = "";
    var style = "dialogWidth:538px; dialogHeight:430px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
    window.showModalDialog(path, parameter, style);
    window.location.reload();

}
//弹出窗口(楼盘详细信息)
function ShowDialogs(url, id) {
    var path = "../CM/" + url + "?id=" + id;
    var parameter = "客源跟进";
    var style = "dialogWidth:660px; dialogHeight:400px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
    window.showModalDialog(path, parameter, style);

}
function Select() {
    starttime = document.getElementById("txtStartDate").value;
    endtime = document.getElementById("txtEndDate").value;
    if (starttime == "" && endtime == "") {
        alert("请输入时间段");
        return;
    }
    starttime = starttime + " 00:00:00";
    endtime = endtime + " 23:59:59";
    SelectResultList(currentPage);




}

// 查看详情
function openDetail(id) {
    $("tr").removeClass("selected");
    $("#tr_" + id).addClass("selected");

    var url = "../PM/HousingDetail.aspx?id=" + id;

    self.parent.closeTab('盘源详情');
    self.parent.addTab('盘源详情', url, 'icon-nav');
    //window.open("HousingDetail.aspx?id=" + id + "&id_list=" + escape(id_list), "target", LexunJS.openParams());    
}
